home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / trans_f.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  36KB  |  1,584 lines

  1. /*****************************************************************************
  2.   FILE           : trans_f.c
  3.   SHORTNAME      : 
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : SNNS-Kernel transfer functions
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Niels Mache
  10.   DATE           : 25.06.90
  11.  
  12.   CHANGED BY     : Sven Doering, Ralf Huebner, Marc Seemann (Uni Tuebingen)
  13.   IDENTIFICATION : @(#)trans_f.c    1.29 3/15/94
  14.   SCCS VERSION   : 1.29
  15.   LAST CHANGE    : 3/15/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20. #include <stdio.h>
  21. #include <math.h>
  22. #include <values.h>
  23. #include <string.h>
  24.  
  25. #include "kr_typ.h"        /*    Kernel types and constants  */
  26. #include "kr_const.h"       /*  Constant Declarators for SNNS-Kernel  */
  27. #include "func_mac.h"        /*    Transfer function macros  */
  28. #include "glob_typ.h"
  29. #include "kr_mac.h"
  30. #include "cc_mac.h" 
  31.  
  32. #include "trans_f.ph"
  33.  
  34. #ifdef  __BORLANDC__
  35. #pragma option -w-
  36. #endif
  37.  
  38. /*#################################################
  39.  
  40. GROUP: Aritmetic Functions
  41.  
  42. #################################################*/
  43.  
  44. /*  exp function that prevents from over- and underflow, that means
  45.     exp_s ist a "save" exp function.
  46. */
  47. static float exp_s( float arg )
  48. {
  49.   if (arg > 88.72) return( MAXFLOAT );
  50.   else if (arg < -102.0) return( MINFLOAT );
  51.   return( exp( arg ) );
  52. }
  53.  
  54.  
  55. /*#################################################
  56.  
  57. GROUP: Unit Output Functions
  58.  
  59. #################################################*/
  60.  
  61. /*  Linear Output Function
  62.     This function isn't used now, because the identity output function is
  63.     the NULL pointer.
  64. */
  65. FlintType  OUTP_Identity(register FlintType activation)
  66. {
  67.   return( activation );
  68. }
  69.  
  70.  
  71. /*  Clipping [0,1] function
  72. */
  73. FlintType  OUT_Clip_01(register FlintType activation)
  74. {
  75.   if (activation < 0.0)  return( (FlintType) 0.0 );
  76.   if (activation > 1.0)  return( (FlintType) 1.0 );
  77.   return( activation );
  78. }
  79.  
  80.  
  81. /*  Clipping [-1,1] function
  82. */
  83. FlintType  OUT_Clip_11(register FlintType activation)
  84. {
  85.   if (activation < -1.0)  return( (FlintType) -1.0 );
  86.   if (activation > 1.0)  return( (FlintType) 1.0 );
  87.   return( activation );
  88. }
  89.  
  90. /*  Threshold 0.5 Output Function
  91. */
  92. FlintType  OUT_Threshold05(register FlintType activation)
  93. {
  94.   if (activation < 0.5)  return( (FlintType) 0.0 );
  95.   return( (FlintType) 1.0 );
  96. }
  97.  
  98.  
  99. /*#################################################
  100.  
  101. GROUP: Unit Activation Functions
  102.  
  103. #################################################*/
  104.  
  105.  
  106. /*  Linear Activation Function
  107. */
  108. FlintType   ACT_Linear(struct Unit *unit_ptr)
  109. {
  110.   ACT_FUNC_DEFS
  111.   register FlintType  sum;
  112.  
  113.  
  114.   sum =  0.0;
  115.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  116.     do
  117.       sum += GET_WEIGHTED_OUTPUT;
  118.     while (GET_NEXT_LINK);
  119.   else
  120.     if (GET_FIRST_SITE( unit_ptr ))
  121.       do
  122.     sum += GET_SITE_VALUE;
  123.       while (GET_NEXT_SITE);
  124.  
  125.   return( sum );
  126. }
  127.  
  128. /*  Brain-State-in-a-Box Function
  129. */
  130. FlintType   ACT_BSBFunction(struct Unit *unit_ptr)
  131. {
  132.   ACT_FUNC_DEFS
  133.   register FlintType  sum;
  134.  
  135.  
  136.   sum =  0.0;
  137.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  138.     do
  139.       sum += GET_WEIGHTED_OUTPUT;
  140.     while (GET_NEXT_LINK);
  141.   else
  142.     if (GET_FIRST_SITE( unit_ptr ))
  143.       do
  144.     sum += GET_SITE_VALUE;
  145.       while (GET_NEXT_SITE);
  146.  
  147.   return( sum * GET_UNIT_BIAS( unit_ptr ));
  148. }
  149.  
  150. /*  Minimum Function (Unit's output and weight)
  151. */
  152. FlintType   ACT_MinOutPlusWeight(struct Unit *unit_ptr)
  153. {
  154.   ACT_FUNC_DEFS
  155.   register FlintType  min1, min2;
  156.  
  157.  
  158.   min1 = 0.0;
  159.  
  160.   if (GET_FIRST_UNIT_LINK( unit_ptr ))  {
  161.     min1 = GET_OUTPUT + GET_WEIGHT;
  162.     while (GET_NEXT_LINK)
  163.       if ((min2 = GET_OUTPUT + GET_WEIGHT) < min1)
  164.     min1 = min2;
  165.   }
  166.   else
  167.     if (GET_FIRST_SITE( unit_ptr ))  {
  168.       min1 = GET_SITE_VALUE;
  169.       while (GET_NEXT_SITE)
  170.        if ((min2 = GET_SITE_VALUE) < min1)
  171.         min1 = min2;
  172.     }
  173.  
  174.   return( min1 );
  175. }
  176.  
  177.  
  178. /*  Hyperbolic Tangent Function
  179. */
  180. FlintType   ACT_TanHFunction(struct Unit *unit_ptr)
  181. {
  182.   ACT_FUNC_DEFS
  183.   register FlintType  sum;
  184.  
  185.  
  186.   sum =  0.0;
  187.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  188.     do
  189.       sum += GET_WEIGHTED_OUTPUT;
  190.     while (GET_NEXT_LINK);
  191.   else
  192.     if (GET_FIRST_SITE( unit_ptr ))
  193.       do
  194.     sum += GET_SITE_VALUE;
  195.       while (GET_NEXT_SITE);
  196.  
  197.   return( tanh( sum + GET_UNIT_BIAS( unit_ptr )));
  198. }
  199.  
  200.  
  201. /*  Hyperbolic Tangent Function plus the bias
  202. */
  203. FlintType   ACT_TanHFunctionPlusBias(struct Unit *unit_ptr)
  204. {
  205.   ACT_FUNC_DEFS
  206.   register FlintType  sum;
  207.  
  208.  
  209.   sum =  0.0;
  210.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  211.     do
  212.       sum += GET_WEIGHTED_OUTPUT;
  213.     while (GET_NEXT_LINK);
  214.   else
  215.     if (GET_FIRST_SITE( unit_ptr ))
  216.       do
  217.     sum += GET_SITE_VALUE;
  218.       while (GET_NEXT_SITE);
  219.  
  220.   return( tanh( sum) + GET_UNIT_BIAS( unit_ptr ));
  221. }
  222.  
  223.  
  224.  
  225. /*  Hyperbolic Tangent Function of (unit_ptr/2)
  226. */
  227. FlintType   ACT_TanHFunction_Xdiv2( unit_ptr )
  228. UNIT_PTR    unit_ptr;
  229. {
  230.   ACT_FUNC_DEFS
  231.   register FlintType  sum;
  232.    float expon;
  233.    float wert;
  234.  
  235.   sum =  0.0;
  236.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  237.     do
  238.       sum += GET_WEIGHTED_OUTPUT;
  239.     while (GET_NEXT_LINK);
  240.   else
  241.     if (GET_FIRST_SITE( unit_ptr ))
  242.       do
  243.     sum += GET_SITE_VALUE;
  244.       while (GET_NEXT_SITE);
  245.   
  246.   wert =  sum + GET_UNIT_BIAS( unit_ptr );
  247.   if( wert > 9 )  wert = 9;
  248.   if( wert <  -9 )  wert = -9;
  249.  
  250.   expon = exp_s(wert);
  251.   return( (expon - 1) / (expon + 1));   
  252.  
  253. }
  254.  
  255.  
  256.  
  257.  
  258. /*  Sigmoid Function
  259. */
  260. FlintType   ACT_Logistic(struct Unit *unit_ptr)
  261. {
  262.   ACT_FUNC_DEFS
  263.   register FlintType  sum;
  264.  
  265.  
  266.   sum =  0.0;
  267.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  268.     do
  269.       sum += GET_WEIGHTED_OUTPUT;
  270.     while (GET_NEXT_LINK);
  271.   else
  272.     if (GET_FIRST_SITE( unit_ptr ))
  273.       do
  274.     sum += GET_SITE_VALUE;
  275.       while (GET_NEXT_SITE);
  276.  
  277.   return( (FlintType) (1.0 / (1.0 + exp_s( -sum - GET_UNIT_BIAS( unit_ptr )))) );
  278. }
  279.  
  280.  
  281. /*  Elliott Function
  282. */
  283. FlintType   ACT_Elliott(struct Unit *unit_ptr)
  284. {
  285.   ACT_FUNC_DEFS
  286.   register FlintType  sum;
  287.  
  288.  
  289.   sum =  0.0;
  290.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  291.     do
  292.       sum += GET_WEIGHTED_OUTPUT;
  293.     while (GET_NEXT_LINK);
  294.   else
  295.     if (GET_FIRST_SITE( unit_ptr ))
  296.       do
  297.     sum += GET_SITE_VALUE;
  298.       while (GET_NEXT_SITE);
  299.  
  300.   sum += GET_UNIT_BIAS(unit_ptr);
  301.   if (sum <= 0.0)
  302.       return (FlintType) sum/(1.0 - sum);
  303.   else
  304.       return (FlintType) sum/(1.0 + sum);
  305. }
  306.  
  307.  
  308. /*  Perceptron Function
  309. */
  310. FlintType   ACT_Perceptron(struct Unit *unit_ptr)
  311. {
  312.   ACT_FUNC_DEFS
  313.   register FlintType  sum;
  314.  
  315.  
  316.   sum =  0.0;
  317.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  318.     do
  319.       sum += GET_WEIGHTED_OUTPUT;
  320.     while (GET_NEXT_LINK);
  321.   else
  322.     if (GET_FIRST_SITE( unit_ptr ))
  323.       do
  324.     sum += GET_SITE_VALUE;
  325.       while (GET_NEXT_SITE);
  326.  
  327.   if (sum >= GET_UNIT_BIAS(unit_ptr))
  328.     return( (FlintType) 1.0 );
  329.  
  330.   return( (FlintType) 0.0 );
  331. }
  332.  
  333. /*  Signum Function
  334. */
  335. FlintType   ACT_Signum(struct Unit *unit_ptr)
  336. {
  337.   ACT_FUNC_DEFS
  338.   register FlintType  sum;
  339.  
  340.  
  341.   sum =  0.0;
  342.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  343.     do
  344.       sum += GET_WEIGHTED_OUTPUT;
  345.     while (GET_NEXT_LINK);
  346.   else
  347.     if (GET_FIRST_SITE( unit_ptr ))
  348.       do
  349.     sum += GET_SITE_VALUE;
  350.       while (GET_NEXT_SITE);
  351.  
  352.   if (sum > 0.0)
  353.     return( (FlintType) 1.0 );
  354.  
  355.   return( (FlintType) -1.0 );
  356. }
  357.  
  358.  
  359. /*  Signum0 Function
  360. */
  361. FlintType   ACT_Signum0(struct Unit *unit_ptr)
  362. {
  363.   ACT_FUNC_DEFS
  364.   register FlintType  sum;
  365.  
  366.  
  367.   sum =  0.0;
  368.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  369.     do
  370.       sum += GET_WEIGHTED_OUTPUT;
  371.     while (GET_NEXT_LINK);
  372.   else
  373.     if (GET_FIRST_SITE( unit_ptr ))
  374.       do
  375.     sum += GET_SITE_VALUE;
  376.       while (GET_NEXT_SITE);
  377.  
  378.   if (sum > 0.0)  return( (FlintType) 1.0 );
  379.   if (sum < 0.0)  return( (FlintType) -1.0 );
  380.   return( (FlintType) 0.0 );
  381. }
  382.  
  383.  
  384. /*  Step Function
  385. */
  386. FlintType   ACT_StepFunction(struct Unit *unit_ptr)
  387. {
  388.   ACT_FUNC_DEFS
  389.   register FlintType  sum;
  390.  
  391.  
  392.   sum =  0.0;
  393.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  394.     do
  395.       sum += GET_WEIGHTED_OUTPUT;
  396.     while (GET_NEXT_LINK);
  397.   else
  398.     if (GET_FIRST_SITE( unit_ptr ))
  399.       do
  400.     sum += GET_SITE_VALUE;
  401.       while (GET_NEXT_SITE);
  402.  
  403.   if (sum > 0.0)  return( (FlintType) 1.0 );
  404.   return( (FlintType) 0.0 );
  405. }
  406.  
  407.  
  408. /*  Hysteresis Step Function
  409. */
  410. FlintType   ACT_HystStepFunction(struct Unit *unit_ptr)
  411. {
  412.   ACT_FUNC_DEFS
  413.   register FlintType  sum;
  414.            FlintType  Schwellwert = 0.1;
  415.  
  416.   sum =  0.0;
  417.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  418.     do
  419.       sum += GET_WEIGHTED_OUTPUT;
  420.     while (GET_NEXT_LINK);
  421.   else
  422.     if (GET_FIRST_SITE( unit_ptr ))
  423.       do
  424.     sum += GET_SITE_VALUE;
  425.       while (GET_NEXT_SITE);
  426.  
  427.   if  (sum - (unit_ptr->bias) > Schwellwert)   return( (FlintType) 1.0 );
  428.   if  (sum - (unit_ptr->bias) < -Schwellwert)  return( (FlintType) 0.0 );
  429.  
  430.   return( unit_ptr->act );
  431. }
  432.  
  433. /*  Bi-Directional Associative Memory
  434. */
  435. FlintType   ACT_BAMFunction(struct Unit *unit_ptr)
  436. {
  437.   ACT_FUNC_DEFS
  438.   register FlintType  sum;
  439.  
  440.  
  441.   sum =  0.0;
  442.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  443.     do
  444.       sum += GET_WEIGHTED_OUTPUT;
  445.     while (GET_NEXT_LINK);
  446.   else
  447.     if (GET_FIRST_SITE( unit_ptr ))
  448.       do
  449.     sum += GET_SITE_VALUE;
  450.       while (GET_NEXT_SITE);
  451.  
  452.   if (sum > 0.0)  return( (FlintType) 1.0 );
  453.   if (sum < 0.0)  return( (FlintType) -1.0 );
  454.   return( unit_ptr->Out.output );
  455. }
  456.  
  457. /* Rummelhart-McClelland's activation function for the delta rule
  458. */
  459. FlintType ACT_RM (struct Unit *unit_ptr)
  460. {
  461.     ACT_FUNC_DEFS
  462.     register FlintType RM_act, sum;
  463.     FlintType Eparam=.15, Dparam=.15;
  464.  
  465.     sum = 0.0;
  466.  
  467.     if (GET_FIRST_UNIT_LINK (unit_ptr))
  468.     do
  469.         sum += GET_WEIGHTED_OUTPUT;
  470.     while (GET_NEXT_LINK);
  471.     else
  472.     if (GET_FIRST_SITE (unit_ptr))
  473.         do
  474.         sum += GET_SITE_VALUE;
  475.         while (GET_NEXT_SITE);
  476.  
  477.     if (sum > 0)
  478.     RM_act = (unit_ptr->act + (Eparam * sum * (1 - unit_ptr->act)) 
  479.           - (Dparam * unit_ptr->act));
  480.     else
  481.     RM_act = (unit_ptr->act + (Eparam * sum * (unit_ptr->act + 1)) 
  482.           - (Dparam * unit_ptr->act));
  483.     
  484.     return (RM_act);
  485. }  
  486.  
  487.  
  488.  
  489. /*  demonstation function: this function act like the Logistic function,
  490.     but the site with the name "Inhibit" will be skipped.
  491. */
  492. FlintType   ACT_LogisticI(struct Unit *unit_ptr)
  493. {
  494.   ACT_FUNC_DEFS
  495.   register FlintType  sum;
  496.  
  497.  
  498.   sum = 0.0;
  499.   if (GET_FIRST_SITE( unit_ptr ))
  500.     /*    Do not calculate the 'Inhibit' site */
  501.     do
  502.       if (strcmp( "Inhibit", GET_SITE_NAME ))
  503.         sum += GET_SITE_VALUE;
  504.     while (GET_NEXT_SITE);
  505.   else
  506.     if (GET_FIRST_UNIT_LINK( unit_ptr ))
  507.       do
  508.         sum += GET_WEIGHTED_OUTPUT;
  509.       while (GET_NEXT_LINK);
  510.  
  511.   return( (FlintType) (1.0 / (1.0 + exp_s( -sum - GET_UNIT_BIAS( unit_ptr )))) );
  512. }
  513.  
  514. /* help function for all Radial Basis Activation, Derivation and Learn
  515.  * functions. Computes the square of the L2-Norm of (T - X), where T is the
  516.  * vector of all weights from links leading to <unit_ptr> and X is the
  517.  * vector of output units the links are connected from.
  518.  * Store calculated value into value_a field of the current unit.
  519.  * ALL FUTURE RBF ACTIVATION FUNCTIONS HAVE TO CALL THIS FUNCTION !!!!!!!!!!
  520.  */
  521.  
  522. FlintType RbfUnitGetNormsqr(struct Unit *unit_ptr)
  523. {
  524.         ACT_FUNC_DEFS
  525.         register FlintType      norm_2 = 0.0;   /* |X - T|^2            */
  526.         register FlintType      diff;           /* difference           */
  527.  
  528.  
  529.         if (!GET_FIRST_UNIT_LINK(unit_ptr))
  530.         {
  531.                 fprintf(stderr,"No input links!\n");
  532.                 return norm_2;
  533.         }
  534.  
  535.         do
  536.         {
  537.                 diff = GET_OUTPUT - GET_WEIGHT;
  538.                 norm_2 += diff * diff;
  539.         }
  540.         while (GET_NEXT_LINK);
  541.  
  542.       return unit_ptr -> value_a = norm_2;
  543. }
  544.  
  545. /*
  546.  * Gaussian RBF Activation function: h(L2, s) = exp(-s*L2^2)
  547.  * where L2 is the L2 Norm (see RbfUnitGetNormsqr), and s is the bias 
  548.  * of <unit_ptr>.
  549.  */
  550.  
  551. FlintType   ACT_RBF_Gaussian(struct Unit *unit_ptr)
  552. {
  553.         register FlintType      norm_2;
  554.  
  555.         norm_2 = RbfUnitGetNormsqr(unit_ptr);
  556.         return (FlintType) exp_s(- GET_UNIT_BIAS(unit_ptr)*norm_2);
  557. }
  558.  
  559. /*
  560.  * Multiquadratic Activation function: h(L2, s) = sqrt(s^2 + L2^2)
  561.  */
  562.  
  563. FlintType ACT_RBF_Multiquadratic(struct Unit *unit_ptr)
  564. {
  565.       register FlintType      norm_2;
  566.  
  567.       norm_2 = RbfUnitGetNormsqr(unit_ptr);
  568.       return (FlintType) sqrt(norm_2 + GET_UNIT_BIAS(unit_ptr));
  569. }
  570.  
  571. /*
  572.  * Thin plate splines Activation function: h(L2, s) = (L2*s)^2*ln(L2*s)
  573.  */
  574.  
  575. FlintType ACT_RBF_Thinplatespline(struct Unit *unit_ptr)
  576. {
  577.       register FlintType      norm_2;
  578.       register FlintType      bias;
  579.  
  580.       norm_2 = RbfUnitGetNormsqr(unit_ptr);
  581.       bias = GET_UNIT_BIAS(unit_ptr);
  582.  
  583.       if (norm_2 == (FlintType) 0.0)
  584.           return (FlintType) 0.0;
  585.       else
  586.           return (FlintType) bias*bias*norm_2*(0.5*log(norm_2) + log(bias));
  587. }
  588.  
  589. /*  Linear Activation Function + BIAS
  590. */
  591. FlintType   ACT_Linear_bias(struct Unit *unit_ptr)
  592. {
  593.   ACT_FUNC_DEFS
  594.   register FlintType  sum;
  595.  
  596.  
  597.   sum =  0.0;
  598.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  599.     do
  600.       sum += GET_WEIGHTED_OUTPUT;
  601.     while (GET_NEXT_LINK);
  602.   else
  603.     if (GET_FIRST_SITE( unit_ptr ))
  604.       do
  605.       sum += GET_SITE_VALUE;
  606.       while (GET_NEXT_SITE);
  607.  
  608.   return( sum + GET_UNIT_BIAS(unit_ptr));
  609. }
  610.  
  611.  
  612.  
  613. /* NOTE: This function is nothing but a threshold function,
  614.    which checks, whether the netinput is greater or equal 2, and if so
  615.    returns 1.0, else 0.0 .
  616. */
  617. FlintType  ACT_at_least_2 (struct Unit *unit_ptr)
  618. {
  619.    ACT_FUNC_DEFS
  620.    register FlintType    sum = 0.0;
  621.  
  622.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  623.       do {
  624.          sum += GET_WEIGHTED_OUTPUT;
  625.       } while (GET_NEXT_LINK);
  626.    } else {
  627.       if (GET_FIRST_SITE (unit_ptr)) {
  628.          do {
  629.             sum += GET_SITE_VALUE;
  630.          } while (GET_NEXT_SITE);
  631.       } /*if*/
  632.    } /*if*/
  633.  
  634.  
  635.    if (sum >= 2.0) {
  636.       return ( (FlintType) 1.0);
  637.    } else {
  638.       return ( (FlintType) 0.0);
  639.    } /*if*/
  640. } /* ACT_at_least_2 */
  641.  
  642.  
  643.  
  644. FlintType  ACT_less_than_0 (struct Unit *unit_ptr)
  645. {
  646.    ACT_FUNC_DEFS
  647.    register FlintType    sum = 0.0;
  648.  
  649.  
  650.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  651.       do {
  652.          sum += GET_WEIGHTED_OUTPUT;
  653.       } while (GET_NEXT_LINK);
  654.    } else {
  655.       if (GET_FIRST_SITE (unit_ptr)) {
  656.          do {
  657.             sum += GET_SITE_VALUE;
  658.          } while (GET_NEXT_SITE);
  659.       } /*if*/
  660.    } /*if*/
  661.  
  662.    if (sum >= 0.0) {
  663.       return ( (FlintType) 0.0);
  664.    } else {
  665.       return ( (FlintType) 1.0);
  666.    } /*if*/
  667.  
  668. } /* ACT_less_than_0 */
  669.  
  670.  
  671.  
  672.  
  673.  
  674. FlintType  ACT_at_least_1 (struct Unit *unit_ptr)
  675. {
  676.    ACT_FUNC_DEFS
  677.    register FlintType   sum = 0.0;
  678.  
  679.  
  680.    if (GET_FIRST_SITE (unit_ptr)) {
  681.       do {
  682.          sum += GET_SITE_VALUE;
  683.       } while (GET_NEXT_SITE);
  684.    } else {
  685.       if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  686.          do {
  687.             sum += GET_WEIGHTED_OUTPUT;
  688.          } while (GET_NEXT_LINK);
  689.       } /*if*/
  690.    } /*if*/
  691.  
  692.  
  693.    if (sum >= 1.0) {
  694.       return ( (FlintType) 1.0);
  695.    } else {
  696.       return ( (FlintType) 0.0);
  697.    } /*if*/
  698.  
  699. } /* ACT_at_least_1 */
  700.  
  701.  
  702.  
  703. FlintType  ACT_at_most_0 (struct Unit *unit_ptr)
  704. {
  705.    ACT_FUNC_DEFS
  706.    register FlintType    sum = 0.0;
  707.  
  708.  
  709.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  710.       do {
  711.          sum += GET_WEIGHTED_OUTPUT;
  712.       } while (GET_NEXT_LINK);
  713.    } else {
  714.       if (GET_FIRST_SITE (unit_ptr)) {
  715.          do {
  716.             sum += GET_SITE_VALUE;
  717.          } while (GET_NEXT_SITE);
  718.       } /*if*/
  719.    } /*if*/
  720.  
  721.    if (sum > 0.0) {
  722.       return ( (FlintType) 0.0);
  723.    } else {
  724.       return ( (FlintType) 1.0);
  725.    } /*if*/
  726.  
  727. } /* ACT_at_most_0 */
  728.  
  729.  
  730.  
  731. FlintType  ACT_Product (struct Unit *unit_ptr)
  732. {
  733.    ACT_FUNC_DEFS
  734.    register FlintType    prod = 1.0;
  735.  
  736.  
  737.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  738.       do {
  739.          prod *= GET_WEIGHTED_OUTPUT;
  740.          if (prod == 0.0) {
  741.             break;
  742.          } /*if*/
  743.       } while (GET_NEXT_LINK);
  744.    } else {
  745.       if (GET_FIRST_SITE (unit_ptr)) {
  746.          do {
  747.             prod *= GET_SITE_VALUE;
  748.             if (prod == 0.0) {
  749.                break;
  750.             } /*if*/
  751.          } while (GET_NEXT_SITE);
  752.       } /*if*/
  753.    } /*if*/
  754.  
  755.    return (prod);
  756.  
  757. } /* ACT_Product () */
  758.  
  759.  
  760. FlintType  ACT_exactly_1 (struct Unit *unit_ptr)
  761. {
  762.    ACT_FUNC_DEFS
  763.    register FlintType    sum = 0.0;
  764.  
  765.  
  766.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  767.       do {
  768.          sum += GET_WEIGHTED_OUTPUT;
  769.       } while (GET_NEXT_LINK);
  770.    } else {
  771.       if (GET_FIRST_SITE (unit_ptr)) {
  772.          do {
  773.             sum += GET_SITE_VALUE;
  774.          } while (GET_NEXT_SITE);
  775.       } /*if*/
  776.    } /*if*/
  777.  
  778.    if ((sum > 0.8) && (sum < 1.2)) {
  779.       return (1.0);
  780.    } else {
  781.       return (0.0);
  782.    } /*if*/
  783.  
  784. } /* ACT_exactly_1 */
  785.  
  786. /*****************************************************************************
  787.   FUNCTION : ACT_TD_Logistic
  788.  
  789.   PURPOSE  : logistic activation function for use in time delay networks
  790.   RETURNS  : activation
  791.   NOTES    : the TD section of the unit must be initialized correct
  792.              the units must be sorted TOPOLOGIC_LOGICAL
  793.  
  794.   UPDATE   : 19.2.93 M. Vogt
  795. ******************************************************************************/
  796.  
  797. FlintType   ACT_TD_Logistic(struct Unit *unit_ptr)
  798. {
  799. /* the common macros are not used */
  800.  
  801.   register FlintType  sum;
  802.   register UNIT_PTR ref_unit;
  803.   register int source_offset;
  804.   register struct Link *link;
  805.  
  806.   if (unit_ptr -> TD.td_connect_typ == 0)
  807.       return ACT_Logistic(unit_ptr);
  808.  
  809.   ref_unit = *(unit_ptr -> TD.my_topo_ptr + unit_ptr -> TD.target_offset);
  810.   source_offset = unit_ptr -> TD.source_offset;
  811.   sum =  0.0;
  812.   if ((ref_unit -> flags) & UFLAG_DLINKS)
  813.   {
  814.       link = (struct Link *) ref_unit->sites;
  815.       while (link != (struct Link *) NULL)
  816.       {
  817.           sum += (*(link->to->TD.my_topo_ptr + source_offset))->Out.output 
  818.                  * link->weight;
  819.           link = link->next;
  820.       }
  821.   }
  822.   else
  823.   {
  824.       fprintf(stderr, 
  825.               "Warning: Illegal link structure used in time delay layer\n");
  826.   }
  827.   return( (FlintType) (1.0 / (1.0 + exp_s( -sum - ref_unit->bias))) );
  828. }
  829.  
  830. /*****************************************************************************
  831.   FUNCTION : ACT_TD_Elliott
  832.  
  833.   PURPOSE  : elliott activation function for use in time delay networks
  834.   RETURNS  : activation
  835.   NOTES    : the TD section of the unit must be initialized correct
  836.              the units must be sorted TOPOLOGIC_LOGICAL
  837.  
  838.   UPDATE   : 5.3.93 M. Vogt
  839. ******************************************************************************/
  840.  
  841. FlintType   ACT_TD_Elliott(struct Unit *unit_ptr)
  842. {
  843. /* the common macros are not used */
  844.  
  845.   register FlintType  sum;
  846.   register UNIT_PTR ref_unit;
  847.   register int source_offset;
  848.   register struct Link *link;
  849.  
  850.   if (unit_ptr -> TD.td_connect_typ == 0)
  851.       return ACT_Elliott(unit_ptr);
  852.  
  853.   ref_unit = *(unit_ptr -> TD.my_topo_ptr + unit_ptr -> TD.target_offset);
  854.   source_offset = unit_ptr -> TD.source_offset;
  855.   sum =  0.0;
  856.   if ((ref_unit -> flags) & UFLAG_DLINKS)
  857.   {
  858.       link = (struct Link *) ref_unit->sites;
  859.       while (link != (struct Link *) NULL)
  860.       {
  861.           sum += (*(link->to->TD.my_topo_ptr + source_offset))->Out.output 
  862.                  * link->weight;
  863.           link = link->next;
  864.       }
  865.   }
  866.   else
  867.   {
  868.       fprintf(stderr, 
  869.               "Warning: Illegal link structure used in time delay layer\n");
  870.   }
  871.  
  872.   sum += ref_unit->bias;
  873.   if (sum <= 0.0)
  874.       return (FlintType) sum/(1.0 - sum);
  875.   else
  876.       return (FlintType) sum/(1.0 + sum);
  877. }
  878.  
  879.  
  880.  
  881. /* This function is called by a xgui function for kohonen networks */
  882. void kohonen_SetExtraParameter(int x)
  883.   /* no. of layer chosen in remote panel */
  884. {
  885.   ExtraParameter=x;
  886. }
  887.  
  888.  
  889. /* Activate specific layer of the net chosen in the remote panel, to set
  890. the layer call:  kohonen_SetExtraParameter( Layer ) 
  891. */
  892. FlintType   ACT_Component( UNIT_PTR unit_ptr )
  893.  
  894. {
  895.   ACT_FUNC_DEFS
  896.   register FlintType  sum;
  897.   int i=1,n;
  898.  
  899.   n = ExtraParameter;
  900.  
  901.   sum =  0.0;
  902.   if (GET_FIRST_SITE( unit_ptr ))
  903.     sum = GET_SITE_VALUE;
  904.   else
  905.     if (GET_FIRST_UNIT_LINK( unit_ptr ))
  906.       do
  907.         sum=GET_WEIGHT;
  908.       while((i++<n)&&GET_NEXT_LINK);
  909.  
  910.   return( sum );
  911. }
  912.  
  913. /*  Calculate the simple euclidic distance
  914.     between in-vector and weight-vector for kohonen networks
  915. */
  916. FlintType   ACT_Euclid( UNIT_PTR unit_ptr )
  917.  
  918. {
  919.   ACT_FUNC_DEFS
  920.   register FlintType  dist;
  921.  
  922.   dist=  0.0;
  923.   if (GET_FIRST_SITE( unit_ptr ))
  924.     do
  925.       dist += GET_SITE_VALUE;
  926.     while (GET_NEXT_SITE);
  927.   else
  928.     if (GET_FIRST_UNIT_LINK( unit_ptr ))
  929.       do
  930.         dist += GET_EUCLID_COMP;
  931.       while (GET_NEXT_LINK);
  932.  
  933.   return(sqrt(dist));
  934. }
  935.  
  936.  
  937.  
  938. /*#################################################
  939.  
  940. GROUP: Derivation Functions of the Activation Functions
  941.  
  942. #################################################*/
  943.  
  944. /*  Sigmoid Derivation Function
  945. */
  946. FlintType   ACT_DERIV_Logistic(struct Unit *unit_ptr)
  947. {
  948.     return( GET_UNIT_ACT( unit_ptr ) * (1.0 - GET_UNIT_ACT( unit_ptr )) );
  949. }
  950.  
  951.  
  952. /*  Elliott Derivation Function
  953. */
  954. FlintType   ACT_DERIV_Elliott(struct Unit *unit_ptr)
  955. {
  956.     register FlintType act;
  957.     if ((act = GET_UNIT_ACT(unit_ptr)) <= 0.0)
  958.     act = 1.0 + act;
  959.     else
  960.     act = 1.0 - act;
  961.  
  962.     return (act*act);
  963. }
  964.  
  965.  
  966. /*  Sigmoid Derivation Function for TD Networks
  967. */
  968.  
  969. FlintType   ACT_DERIV_TD_Logistic(struct Unit *unit_ptr)
  970. {
  971.   return( GET_UNIT_ACT( unit_ptr ) * (1.0 - GET_UNIT_ACT( unit_ptr )) );
  972. }
  973.  
  974.  
  975. /*  Elliott Derivation Function for TD Networks
  976. */
  977.  
  978. FlintType   ACT_DERIV_TD_Elliott(struct Unit *unit_ptr)
  979. {
  980.     register FlintType act;
  981.     if ((act = GET_UNIT_ACT(unit_ptr)) <= 0.0)
  982.     act = 1.0 + act;
  983.     else
  984.     act = 1.0 - act;
  985.  
  986.     return (act*act);
  987. }
  988.  
  989.  
  990. /*  Identity Derivation Function
  991. */
  992. FlintType   ACT_DERIV_Identity(struct Unit *unit_ptr)
  993. {
  994.   return( (FlintType) 1.0 );
  995. }
  996.  
  997. /*  Brain-State-in-a-Box Derivation Function
  998. */
  999. FlintType   ACT_DERIV_BSBFunction(struct Unit *unit_ptr)
  1000. {
  1001.   return( GET_UNIT_BIAS( unit_ptr ));
  1002. }
  1003.  
  1004. /* TanH Derivation Function
  1005. */
  1006. FlintType   ACT_DERIV_TanHFunction(struct Unit *unit_ptr)
  1007. {
  1008.   return(1.0-GET_UNIT_ACT( unit_ptr ) * (GET_UNIT_ACT( unit_ptr )) );
  1009. }
  1010.  
  1011.  
  1012. /* TanH Derivation Function
  1013. */
  1014. FlintType   ACT_DERIV_TanHFunction_Xdiv2(struct Unit *unit_ptr)
  1015. {
  1016.   return(1.0-(GET_UNIT_ACT( unit_ptr ) * (GET_UNIT_ACT( unit_ptr )))/2 );
  1017. }
  1018.  
  1019.  
  1020.  
  1021.  
  1022. /*  Dummy function for the derivation functions. Returns always the value 1.0.
  1023.     This function is used for activation functions that can't have a derivation
  1024.     function.
  1025.  
  1026.     NOTE: All activation functions have to provide a derivation function.
  1027. */
  1028. FlintType   ACT_DERIV_Dummy(struct Unit *unit_ptr)
  1029. {
  1030.   return( (FlintType) 1.0 );
  1031. }
  1032.  
  1033. /* Gaussian Radial Basis Derivation functionS
  1034.  * depending on Aux: 0 derivated to T
  1035.  *                   1 derivated to s (BIAS)
  1036.  *                 2 derivated to T if value_a holds norm ^ 2;
  1037.  *                 3 derivated to s if value_a holds norm ^ 2;
  1038.  *                 others: const 1;
  1039.  */
  1040.  
  1041. FlintType   ACT_DERIV_RBF_Gaussian(struct Unit *unit_ptr)
  1042. {
  1043.       register FlintType      rc;             /* return value         */
  1044.       register FlintType      norm_2;         /* norm ^ 2             */
  1045.  
  1046.       switch (unit_ptr -> Aux.int_no)
  1047.       {
  1048.           case 0:
  1049.               /* derivated to norm_2:                                 */
  1050.               norm_2 = RbfUnitGetNormsqr(unit_ptr);
  1051.               rc =  (FlintType) -GET_UNIT_BIAS(unit_ptr)
  1052.                       * exp_s(- GET_UNIT_BIAS(unit_ptr)*norm_2);
  1053.               break;
  1054.           case 1:
  1055.               /* derivated to BIAS:                                   */
  1056.               norm_2 = RbfUnitGetNormsqr(unit_ptr);
  1057.               rc = (FlintType) -norm_2 
  1058.                       * exp_s(- GET_UNIT_BIAS(unit_ptr)*norm_2);
  1059.               break;
  1060.           case 2:
  1061.               /* derivated to norm_2: (norm ^ 2 = value_a)            */
  1062.               rc =  (FlintType) -GET_UNIT_BIAS(unit_ptr)
  1063.                       * exp_s(- GET_UNIT_BIAS(unit_ptr)*unit_ptr -> value_a);
  1064.               break;
  1065.           case 3:
  1066.               /* derivated to BIAS: (norm ^ 2 = value_a)              */
  1067.               rc = (FlintType) -unit_ptr -> value_a 
  1068.                       * exp_s(- GET_UNIT_BIAS(unit_ptr)*unit_ptr -> value_a);
  1069.               break;
  1070.           default:
  1071.               rc = (FlintType) 1.0;
  1072.       }
  1073.  
  1074.   return rc;
  1075. }
  1076.  
  1077. /* Multiquadratic Radial Basis Derivation functionS
  1078.  * depending on Aux: 0 derivated to T
  1079.  *                   1 derivated to s (BIAS)
  1080.  *                 2 derivated to T if value_a holds norm ^ 2;
  1081.  *                 3 derivated to s if value_a holds norm ^ 2;
  1082.  *                 others: const 1;
  1083.  */
  1084.  
  1085. FlintType   ACT_DERIV_RBF_Multiquadratic(struct Unit *unit_ptr)
  1086. {
  1087.       register FlintType      rc;             /* return value         */
  1088.       register FlintType      norm_2;         /* norm ^ 2             */
  1089.       register FlintType      bias;           /* s                    */
  1090.  
  1091.       bias = (FlintType) GET_UNIT_BIAS(unit_ptr);
  1092.       switch (unit_ptr -> Aux.int_no)
  1093.       {
  1094.           case 0:
  1095.           case 1:
  1096.               /* derivated to BIAS:                                   */
  1097.               /* derivated to norm_2:                                 */
  1098.               norm_2 = RbfUnitGetNormsqr(unit_ptr);
  1099.               rc =  (FlintType) 1.0/(2.0 * sqrt(bias + norm_2));
  1100.               break;
  1101.           case 2:
  1102.           case 3:
  1103.               /* derivated to BIAS: (norm ^ 2 = value_a)              */
  1104.               /* derivated to norm_2: (norm ^ 2 = value_a)            */
  1105.               rc =  (FlintType) 1.0/(2.0 * sqrt(bias + unit_ptr -> value_a));
  1106.               break;
  1107.           default:
  1108.               rc = (FlintType) 1.0;
  1109.       }
  1110.  
  1111.   return rc;
  1112. }
  1113.  
  1114. /* Thin Plate Spline Radial Basis Derivation functionS
  1115.  * depending on Aux: 0 derivated to T
  1116.  *                   1 derivated to s (BIAS)
  1117.  *                 2 derivated to T if value_a holds norm ^ 2;
  1118.  *                 3 derivated to s if value_a holds norm ^ 2;
  1119.  *                 others: const 1;
  1120.  */
  1121.  
  1122. FlintType   ACT_DERIV_RBF_Thinplatespline(struct Unit *unit_ptr)
  1123. {
  1124.       register FlintType      rc;             /* return value         */
  1125.       register FlintType      norm_2;         /* norm ^ 2             */
  1126.       register FlintType      bias;           /* s                    */
  1127.  
  1128.       bias = (FlintType) GET_UNIT_BIAS(unit_ptr);
  1129.       switch (unit_ptr -> Aux.int_no)
  1130.       {
  1131.           case 0:
  1132.               /* derivated to norm_2:                                 */
  1133.               norm_2 = RbfUnitGetNormsqr(unit_ptr);
  1134.               if (norm_2 == (FlintType) 0.0)
  1135.                   rc = (FlintType) 0.0;
  1136.               else
  1137.                   rc =  (FlintType) bias * bias *
  1138.                       (log(norm_2) + 2.0*log(bias) + 1.0) / 2.0;
  1139.               break;
  1140.           case 1:
  1141.               /* derivated to BIAS:                                   */
  1142.               norm_2 = RbfUnitGetNormsqr(unit_ptr);
  1143.               if (norm_2 == (FlintType) 0.0)
  1144.                   rc = (FlintType) 0.0;
  1145.               else
  1146.                   rc = (FlintType) bias * norm_2 *
  1147.                       (log(norm_2) + 2.0*log(bias) + 1.0);
  1148.               break;
  1149.           case 2:
  1150.               /* derivated to norm_2: (norm ^ 2 = value_a)            */
  1151.               if (unit_ptr -> value_a == (FlintType) 0.0)
  1152.                   rc = (FlintType) 0.0;
  1153.               else
  1154.                   rc =  (FlintType) bias * bias *
  1155.                       (log(unit_ptr -> value_a) + 2.0*log(bias) + 1.0) / 2.0;
  1156.               break;
  1157.           case 3:
  1158.               /* derivated to BIAS: (norm ^ 2 = value_a)              */
  1159.               if (unit_ptr -> value_a == (FlintType) 0.0)
  1160.                   rc = (FlintType) 0.0;
  1161.               else
  1162.                   rc = (FlintType) bias * unit_ptr -> value_a *
  1163.                       (log(unit_ptr -> value_a) + 2.0*log(bias) + 1.0);
  1164.               break;
  1165.           default:
  1166.               rc = (FlintType) 1.0;
  1167.       }
  1168.  
  1169.   return rc;
  1170. }
  1171.  
  1172. /*#################################################
  1173.  
  1174. GROUP: Site functions
  1175.  
  1176. #################################################*/
  1177.  
  1178. /*  Linear Site Function
  1179. */
  1180. FlintType  SITE_WeightedSum(struct Site *site_ptr)
  1181. {
  1182.   SITE_FUNC_DEFS
  1183.   register FlintType  sum;
  1184.  
  1185.  
  1186.   sum = 0.0;
  1187.   if (GET_FIRST_SITE_LINK( site_ptr ))
  1188.     do
  1189.       sum += GET_WEIGHTED_OUTPUT;
  1190.     while (GET_NEXT_LINK);
  1191.  
  1192.   return( sum );
  1193. }
  1194.  
  1195.  
  1196. /*  Product of all predecessor outputs and input link weights
  1197. */
  1198. FlintType  SITE_Product(struct Site *site_ptr)
  1199. {
  1200.   SITE_FUNC_DEFS
  1201.   register FlintType  prod;
  1202.  
  1203.  
  1204.   if (GET_FIRST_SITE_LINK( site_ptr ))  {
  1205.     prod = 1.0;
  1206.     do
  1207.       prod *= GET_WEIGHTED_OUTPUT;
  1208.     while (GET_NEXT_LINK);
  1209.  
  1210.     return( prod );
  1211.   }
  1212.   else
  1213.     return( (FlintType) 0.0 );
  1214. }
  1215.  
  1216.  
  1217. /*  Like SITE_Product() but no weighting of the unit's output
  1218. */
  1219. FlintType  SITE_ProductA(struct Site *site_ptr)
  1220. {
  1221.   SITE_FUNC_DEFS
  1222.   register FlintType  prod;
  1223.  
  1224.  
  1225.   if (GET_FIRST_SITE_LINK( site_ptr ))  {
  1226.     prod = 1.0;
  1227.     do
  1228.       prod *= GET_OUTPUT;
  1229.     while (GET_NEXT_LINK);
  1230.  
  1231. /*  Future Application (in SNNS-Kernel V2.1 the sites don't have weights).
  1232.     So the return value is only the product.
  1233. */
  1234.     return( GET_SITE_WEIGHT * prod );
  1235.   }
  1236.   else
  1237.     return( (FlintType) 0.0 );
  1238. }
  1239.  
  1240.  
  1241.  
  1242. /*  Get the highest weighted output
  1243. */
  1244. FlintType  SITE_Max(struct Site *site_ptr)
  1245. {
  1246.   SITE_FUNC_DEFS
  1247.   register FlintType  max, out;
  1248.  
  1249.  
  1250.   if (GET_FIRST_SITE_LINK( site_ptr ))  {
  1251.     max = GET_WEIGHTED_OUTPUT;
  1252.  
  1253.     while (GET_NEXT_LINK)  {
  1254.       out = GET_WEIGHTED_OUTPUT;
  1255.       if (max < out)  max = out;
  1256.     }
  1257.  
  1258.     return( max );
  1259.   }
  1260.   else
  1261.     return( (FlintType) 0.0 );
  1262. }
  1263.  
  1264.  
  1265. /*  Get the lowest weighted output
  1266. */
  1267. FlintType  SITE_Min(struct Site *site_ptr)
  1268. {
  1269.   SITE_FUNC_DEFS
  1270.   register FlintType  min, out;
  1271.  
  1272.  
  1273.   if (GET_FIRST_SITE_LINK( site_ptr ))  {
  1274.     min = GET_WEIGHTED_OUTPUT;
  1275.  
  1276.     while (GET_NEXT_LINK)  {
  1277.       out = GET_WEIGHTED_OUTPUT;
  1278.       if (min > out)  min = out;
  1279.     }
  1280.  
  1281.     return( min );
  1282.   }
  1283.   else
  1284.     return( (FlintType) 0.0 );
  1285.  
  1286. }
  1287.  
  1288.  
  1289. FlintType  SITE_at_least_2 (struct Site *site_ptr)
  1290. {
  1291.   SITE_FUNC_DEFS
  1292.   register FlintType  sum = 0.0;
  1293.  
  1294.  
  1295.   sum = 0.0;
  1296.   if (GET_FIRST_SITE_LINK (site_ptr))
  1297.     do
  1298.       sum += GET_WEIGHTED_OUTPUT;
  1299.     while (GET_NEXT_LINK);
  1300.  
  1301.   if (sum >= 2.0) {
  1302.      return ( (FlintType) 1.0);
  1303.   } else {
  1304.      return ( (FlintType) 0.0);
  1305.   } /*if*/
  1306.  
  1307. } /* SITE_at_least_2 */
  1308.  
  1309.  
  1310. FlintType  SITE_at_least_1 (struct Site *site_ptr)
  1311. {
  1312.   SITE_FUNC_DEFS
  1313.   register FlintType  sum = 0.0;
  1314.  
  1315.  
  1316.   sum = 0.0;
  1317.   if (GET_FIRST_SITE_LINK (site_ptr))
  1318.     do
  1319.       sum += GET_WEIGHTED_OUTPUT;
  1320.     while (GET_NEXT_LINK);
  1321.  
  1322.   if (sum >= 1.0) {
  1323.      return ( (FlintType) 1.0);
  1324.   } else {
  1325.      return ( (FlintType) 0.0);
  1326.   } /*if*/
  1327.  
  1328. } /* SITE_at_least_1 */
  1329.  
  1330.  
  1331. FlintType  SITE_at_most_0 (struct Site *site_ptr)
  1332. {
  1333.   SITE_FUNC_DEFS
  1334.   register FlintType  sum = 0.0;
  1335.  
  1336.  
  1337.   sum = 0.0;
  1338.   if (GET_FIRST_SITE_LINK (site_ptr))
  1339.     do
  1340.       sum += GET_WEIGHTED_OUTPUT;
  1341.     while (GET_NEXT_LINK);
  1342.  
  1343.   if (sum <= 0.0) {
  1344.      return ( (FlintType) 1.0);
  1345.   } else {
  1346.      return ( (FlintType) 0.0);
  1347.   } /*if*/
  1348.  
  1349. } /* SITE_at_most_0 */
  1350.  
  1351.  
  1352.  
  1353. /* IMPORTANT:
  1354.    This function doesn't check for overflows. So make sure
  1355.    that sum is greater than 0.0 when using this Site function.
  1356. */
  1357. FlintType  SITE_Reciprocal_WeightedSum (struct Site *site_ptr)
  1358. {
  1359.   SITE_FUNC_DEFS
  1360.   register FlintType  sum = 0.0;
  1361.  
  1362.  
  1363.   sum = 0.0;
  1364.   if (GET_FIRST_SITE_LINK( site_ptr ))
  1365.     do
  1366.       sum += GET_WEIGHTED_OUTPUT;
  1367.     while (GET_NEXT_LINK);
  1368.  
  1369.   if (sum == 0.0) {
  1370.      return (0.0);
  1371.   } else {
  1372.      return((FlintType) (1/sum));
  1373.   } /*if*/
  1374. } /* SITE_Reciprocal_WeightedSum */
  1375.  
  1376.  
  1377.  
  1378. FlintType   ACT_LogisticSym(struct Unit *unit_ptr)
  1379. {
  1380.   ACT_FUNC_DEFS
  1381.   register FlintType  sum;
  1382.  
  1383.  
  1384.   sum =  0.0;
  1385.   if (GET_FIRST_UNIT_LINK( unit_ptr ))
  1386.     do
  1387.       sum += GET_WEIGHTED_OUTPUT;
  1388.     while (GET_NEXT_LINK);
  1389.   else
  1390.     if (GET_FIRST_SITE( unit_ptr ))
  1391.       do
  1392.     sum += GET_SITE_VALUE;
  1393.       while (GET_NEXT_SITE);
  1394.   return( (FlintType) (1.0 / (1.0 + exp_s( -sum - GET_UNIT_BIAS( unit_ptr ))))-0.5);
  1395. }
  1396.  
  1397. FlintType   ACT_DERIV_LogisticSym(struct Unit *unit_ptr)
  1398. {
  1399.   return( 0.25 - GET_UNIT_ACT( unit_ptr ) * GET_UNIT_ACT( unit_ptr ));
  1400. }
  1401.  
  1402. FlintType   ACT_DERIV_tanh(struct Unit *unit_ptr)
  1403. {
  1404.   return( 2 * (1.0 - GET_UNIT_ACT( unit_ptr )) * GET_UNIT_ACT( unit_ptr ));
  1405. }
  1406. FlintType   ACT_RCC_Logistic(struct Unit *unit_ptr)
  1407. {
  1408.   int reset;
  1409.   struct Link *LinkPtr;
  1410.   register FlintType  sum;
  1411.  
  1412.   reset = unit_ptr->lln;
  1413.   sum =  0.0;
  1414.  
  1415.   if(IS_HIDDEN_UNIT(unit_ptr)) {
  1416.     if(!reset){
  1417.       FOR_ALL_LINKS(unit_ptr,LinkPtr){
  1418.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1419.       }
  1420.     }
  1421.     else {
  1422.       FOR_ALL_NOT_RECURRENT_LINKS(unit_ptr,LinkPtr) {
  1423.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1424.       }
  1425.     }
  1426.     return((FlintType)(1.0 / (1.0 + exp_s( -sum - unit_ptr->bias))));
  1427.   }
  1428.   else if(IS_SPECIAL_UNIT(unit_ptr)) {
  1429.     if(!reset){
  1430.       FOR_ALL_LINKS(unit_ptr,LinkPtr){
  1431.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1432.       }
  1433.     }
  1434.     else {
  1435.       FOR_ALL_NOT_RECURRENT_LINKS(unit_ptr,LinkPtr) {
  1436.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1437.       }
  1438.     }
  1439.     return((FlintType)(1.0 / (1.0 + exp_s( -sum - unit_ptr->bias ))));
  1440.   }
  1441.   else if(IS_OUTPUT_UNIT(unit_ptr)){  
  1442.     FOR_ALL_LINKS(unit_ptr,LinkPtr) {
  1443.       sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1444.     }
  1445.   }
  1446.   return( (FlintType) (1.0 / (1.0 + exp_s( -sum - unit_ptr->bias ))));
  1447. }
  1448.  
  1449. FlintType   ACT_RCC_LogisticSym(struct Unit *unit_ptr)
  1450. {
  1451.   int reset;
  1452.   struct Link *LinkPtr;
  1453.   register FlintType  sum;
  1454.  
  1455.   reset = unit_ptr->lln;
  1456.   sum =  0.0;
  1457.  
  1458.   if(IS_HIDDEN_UNIT(unit_ptr)) {
  1459.     if(!reset){
  1460.       FOR_ALL_LINKS(unit_ptr,LinkPtr){
  1461.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1462.       }
  1463.     }
  1464.     else {
  1465.       FOR_ALL_NOT_RECURRENT_LINKS(unit_ptr,LinkPtr) {
  1466.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1467.       }
  1468.     }
  1469.     return ((FlintType) (1.0 / (1.0 + exp_s( -sum - unit_ptr->bias))-0.5));
  1470.   }
  1471.   else if(IS_SPECIAL_UNIT(unit_ptr)) {
  1472.     if(!reset){
  1473.       FOR_ALL_LINKS(unit_ptr,LinkPtr){
  1474.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1475.       }
  1476.     }
  1477.     else {
  1478.       FOR_ALL_NOT_RECURRENT_LINKS(unit_ptr,LinkPtr) {
  1479.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1480.       }
  1481.     }
  1482.     return ((FlintType) (1.0 / (1.0 + exp_s( -sum - unit_ptr->bias))-0.5));
  1483.   }
  1484.   else if(IS_OUTPUT_UNIT(unit_ptr)){  
  1485.     FOR_ALL_LINKS(unit_ptr,LinkPtr) {
  1486.       sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1487.     }
  1488.   }
  1489.   return( (FlintType) ((1.0 / (1.0 + exp_s( -sum - unit_ptr->bias)))-0.5));
  1490. }
  1491.  
  1492. FlintType   ACT_RCC_Tanh(struct Unit *unit_ptr)
  1493. {
  1494.   int reset;
  1495.   struct Link *LinkPtr;
  1496.   register FlintType  sum;
  1497.  
  1498.   reset = unit_ptr->lln;
  1499.   sum =  0.0;
  1500.  
  1501.   if(IS_HIDDEN_UNIT(unit_ptr)) {
  1502.     if(!reset){
  1503.       FOR_ALL_LINKS(unit_ptr,LinkPtr){
  1504.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1505.       }
  1506.     }
  1507.     else {
  1508.       FOR_ALL_NOT_RECURRENT_LINKS(unit_ptr,LinkPtr) {
  1509.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1510.       }
  1511.     }
  1512.     return ((FlintType) tanh(sum + unit_ptr->bias));
  1513.   }
  1514.   else if(IS_SPECIAL_UNIT(unit_ptr)) {
  1515.     if(!reset){
  1516.       FOR_ALL_LINKS(unit_ptr,LinkPtr){
  1517.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1518.       }
  1519.     }
  1520.     else {
  1521.       FOR_ALL_NOT_RECURRENT_LINKS(unit_ptr,LinkPtr) {
  1522.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1523.       }
  1524.     }
  1525.     return ((FlintType) tanh(sum + unit_ptr->bias));
  1526.   }
  1527.   else if(IS_OUTPUT_UNIT(unit_ptr)){  
  1528.     FOR_ALL_LINKS(unit_ptr,LinkPtr) {
  1529.       sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1530.     }
  1531.   }
  1532.   return ((FlintType) tanh(sum + unit_ptr->bias));
  1533. }
  1534.  
  1535. FlintType   ACT_RCC_Linear(struct Unit *unit_ptr)
  1536. {
  1537.   struct Link *LinkPtr;
  1538.   register FlintType  sum;
  1539.   int reset;
  1540.   
  1541.   reset = unit_ptr->lln;
  1542.   sum =  0.0;
  1543.  
  1544.   if(IS_HIDDEN_UNIT(unit_ptr)) {
  1545.     if(!reset){
  1546.       FOR_ALL_LINKS(unit_ptr,LinkPtr){
  1547.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1548.       }
  1549.     }
  1550.     else {
  1551.       FOR_ALL_NOT_RECURRENT_LINKS(unit_ptr,LinkPtr) {
  1552.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1553.       }
  1554.     }
  1555.     return ((FlintType) (sum + unit_ptr->bias));
  1556.   }
  1557.   else if(IS_SPECIAL_UNIT(unit_ptr)) {
  1558.     if(!reset){
  1559.       FOR_ALL_LINKS(unit_ptr,LinkPtr){
  1560.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1561.       }
  1562.     }
  1563.     else {
  1564.       FOR_ALL_NOT_RECURRENT_LINKS(unit_ptr,LinkPtr) {
  1565.         sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1566.       }
  1567.     }
  1568.     return ((FlintType) (sum + unit_ptr->bias));
  1569.   }
  1570.   else if(IS_OUTPUT_UNIT(unit_ptr)){  
  1571.     FOR_ALL_LINKS(unit_ptr,LinkPtr) {
  1572.       sum += LinkPtr->weight * LinkPtr->to->Out.output;
  1573.     }
  1574.   }
  1575.   return ((FlintType) (sum + unit_ptr->bias));
  1576. }
  1577.  
  1578.  
  1579.  
  1580.  
  1581. #ifdef  __BORLANDC__
  1582. #pragma option -w+.
  1583. #endif
  1584.